$(function(){
	$(".banner").thumbnailImg({
	    large_elem: ".large_box",
	    small_elem: ".small_list",
	    left_btn: ".left_btn",
	    right_btn: ".right_btn"
	});
	$('.production-item-mask').click(function(){
		$(this).parents('.production').find('.production-item-more').fadeToggle();
		$(this).parents('.production').find('.production-item-mask').fadeToggle();
	});

	$('.show-total i').click(function(){
		$('.show-total').hide();
		$('.box').css('height','auto');
	});


	doDefault();

    //处理富文本中不要放大的富文本
    $('.rich-text a').each(function(){
        if($(this).attr('href')&&$(this).attr('href')!=''&&$(this).attr('href')!='javascript:void'&&$(this).attr('href')!='javascript:void(0)'){
            $(this).find('img').addClass('no-click-img');
        }
    });
	//点击图片进行预览
    $('img').not(".no-click-img").click(function(){
        var current=$(this).attr('src');
        showImages(current);
    });
})


//获取微信jssdk凭证
function doDefault(successCallBack,errorCallBack) {
    var successCallBack=successCallBack||false; 
    var errorCallBack=errorCallBack||false; 
    $.ajax({
        type: "post",
        url: "CommonApi/CommonWx/getWxJsSdkConfig",
        data: {
            url: window.location.href,
            park_id:$('#park_id').val()
        },
        async: true,
        dataType: 'json',
        success: function(data) {
            if (data.status) {
                var t = JSON.parse(data.v);
                wx.config({
                    beta: true,
                    debug: false,
                    appId: t.appId,
                    timestamp: t.timestamp,
                    nonceStr: t.nonceStr,
                    signature: t.signature,
                    jsApiList: ['checkJsApi',"previewImage"] // 必填，需要使用的JS接口列表
                });
                if(successCallBack){
                    successCallBack();
                }
            } else {
                errorAlert(data.msg);
                if(errorCallBack){
                    errorCallBack();
                }
            }
        }
    });
}


var showImages=function(current){
	// alert(document.domain);
    if(current.substr(0,7).toLowerCase() == "http://"||current.substr(0,8).toLowerCase() == "https://"){
        var current=current;
    }
    else{
    	if(current.substr(0,8).toLowerCase()=='/ueditor'){
    		var current='http://'+document.domain+current;
    	}
    	else if(current.substr(0,1).toLowerCase()=='/'){
    		var current=getRootPath()+current;
    	}
    	else{
    		var current=getRootPath()+'/'+current;
    	}  
    }
    wx.ready(function() {
        wx.checkJsApi({
            jsApiList: ['previewImage'], // 需要检测的JS接口列表，所有JS接口列表见附录2,  
            success: function(res) {
                if (res.checkResult.onMenuShareAppMessage == false) {
                    alert("您的微信版本太低！");
                    return;
                }
            }
        });
        var img=[];
        $('img').not(".no-show-img").each(function(){
            if($(this).attr('src').substr(0,7).toLowerCase() == "http://"||$(this).attr('src').substr(0,8).toLowerCase() == "https://"){
                img.push($(this).attr('src'));
            }
            else{
            	if($(this).attr('src').substr(0,8).toLowerCase()=='/ueditor'){
            		img.push('http://'+document.domain+$(this).attr('src'));
            	}
            	else if($(this).attr('src').substr(0,1).toLowerCase()=='/'){
            		img.push(getRootPath()+$(this).attr('src'));
            	}
            	else{
            		img.push(getRootPath()+'/'+$(this).attr('src'));
            	}    
            } 
        });
        wx.previewImage({
            current: current, // 当前显示图片的http链接
            urls: img // 需要预览的图片http链接列表
        });
    });
}